<?php

namespace App\Http\Controllers\Pm;

use App\Http\Controllers\Pm\BasePmController;
use App\Services\Pm\UserServices;
use Illuminate\Http\Request;
use App\Common\Api\SystemCode;
use App\Common\Api\SystemMessage;
use Symfony\Component\HttpFoundation\Response;

class UserController extends BasePmController
{
    protected UserServices $userServices;
    public function __construct(UserServices $userServices)
    {
        $this->userServices = $userServices;
        parent::__construct();
    }

    /**
     * 用户登录，获取 JWT
     * @param Request $request
     */
    public function login(Request $request)
    {
        //接收验证参数
        $params = $request->only('email', 'password');
        if (empty($params['email']) || empty($params['password'])) {
            return response()->json([
                'code'=>SystemCode::SYSTEM_ERROR_PARAM_NULL,
                'message'=>SystemMessage::SYSTEM_ERROR_PARAM_NULL,
                'data'=>[]
            ])->setStatusCode(Response::HTTP_OK);
        }

        return $this->userServices->login($params);
    }

    /**
     * 刷新Token
     */
    public function refresh()
    {
        return $this->userServices->refresh();
    }

    /**
     * 退出登录，注销JWT;
     */
    public function logout()
    {
        return $this->userServices->logout();
    }

    /**
     * 获取当前JWT对应的用户。
     */
    public function userInfo()
    {
        return $this->userServices->userInfo();
    }
}
